 /************************************************************************************************************
 * @attention
 *
 * Firmware Disclaimer Information
 *
 * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the
 *    code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the
 *    proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and
 *    other intellectual property laws.
 *
 * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the
 *    code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties
 *    other than HOLTEK and the customer.
 *
 * 3. The program technical documentation, including the code, is provided "as is" and for customer reference
 *    only. After delivery by HOLTEK, the customer shall use the program technical documentation, including
 *    the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including
 *    the warranties of merchantability, satisfactory quality and fitness for a particular purpose.
 *
 * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2>
 ************************************************************************************************************/
//Generated by HT32CodeConfig V1.1.3 Build 240823
//-----------------------------------------------------------------------------
#include "ADC.h"

//-----------------------------------------------------------------------------
vu8 adc_result_update;
vu16 adc_result[14];

//-----------------------------------------------------------------------------
void ADC_Configuration(void)
{
  CKCU_PeripClockConfig_TypeDef CKCUClock = {{0}};
  CKCUClock.Bit.ADC   = 1;
  CKCUClock.Bit.AFIO  = 1;
  CKCU_PeripClockConfig(CKCUClock, ENABLE);

  ADC_Reset(HT_ADC);
  CKCU_SetADCPrescaler(CKCU_ADCPRE_DIV64);    // Setting ADCLK frequency

  AFIO_GPxConfig(GPIO_PC, AFIO_PIN_8, AFIO_FUN_ADC);  // Config AFIO mode

  ADC_RegularChannelConfig(HT_ADC, ADC_CH_10, 0);


  ADC_RegularGroupConfig(HT_ADC, ONE_SHOT_MODE, 1, 1);  // Mode, Length , SubLength
  ADC_RegularTrigConfig(HT_ADC, ADC_TRIG_SOFTWARE);     //Trigger mode
  ADC_SamplingTimeConfig(HT_ADC, 0);
  ADC_IntConfig(HT_ADC, ADC_INT_CYCLE_EOC, ENABLE);
  ADC_Cmd(HT_ADC, ENABLE);
  NVIC_EnableIRQ(ADC_IRQn);
  ADC_SoftwareStartConvCmd(HT_ADC, ENABLE);   // Trigger to start
}


//-----------------------------------------------------------------------------
void ADC_IRQHandler(void)
{
  if(ADC_GetIntStatus(HT_ADC, ADC_INT_CYCLE_EOC))
  {
    ADC_ClearIntPendingBit(HT_ADC, ADC_FLAG_CYCLE_EOC);
    adc_result[0] = HT_ADC->DR[0];
    adc_result_update = 1;
    ADC_SoftwareStartConvCmd(HT_ADC, ENABLE);   // Trigger to NEXT start?
  }
}


//-----------------------------------------------------------------------------


